﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Yipusoft.SixAcquaint.BLL;
using Yipusoft.SixAcquaint.Model;
using System.Collections.Generic;

public partial class BasicBase_KeyUnit_KeyPoint : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {

            if (!string.IsNullOrEmpty(Request["kid"]))
            {

                KeyPointInfo keyPoint = KeyUnit.GetKeyPointByID(Request["kid"]);




                txtKeyPointName.Text = keyPoint.KeyPointName;
                txtParms.Text = keyPoint.Parms;
                txtSubstances.Text = keyPoint.Substances;
                txtWhole.Text = keyPoint.Whole;
                txtInHouseStructure.Text = keyPoint.InHouseStructure;
                txtFirePrediction.Text = keyPoint.FirePrediction;
                ddlFireResistanceRating.SelectedValue = keyPoint.FireResistanceRate;
                txtFireDanger.Text = keyPoint.FireDanger;
                //ddlFireResistanceRating.SelectedValue = keyPoint.FireResistanceRate;
                ListPageContral1.Visible = false;
            }
            if (!string.IsNullOrEmpty(Request["uid"]))
            {
                ListPageContral1.SetFirstPage();
                gvKeyPoint.PageIndex = 0;
                BindKeyPointList();
                ListPageContral1.Visible = true;
                KeyUnitInfo kInfo = KeyUnit.GetKeyUnitInfoByID(Request["uid"]);
                hlReturn.NavigateUrl = "InsertKeyUnit.aspx?sid=" + kInfo.StandardID;
                hlReturn.ToolTip = "返回" + kInfo.UnitName;
            }
        }
    }

    protected void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {

        gvKeyPoint.PageIndex = PageIndex;
        BindKeyPointList();
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {

        //判断是否编辑
        if (!string.IsNullOrEmpty(Request["kid"]))
        {
            KeyPointInfo keyPoint = KeyUnit.GetKeyPointByID(Request["kid"]);
            keyPoint.KeyUnitID = keyPoint.KeyUnitID;

            keyPoint.KeyPointName = txtKeyPointName.Text;
            keyPoint.Parms = txtParms.Text;
            keyPoint.Substances = txtSubstances.Text;
            keyPoint.Whole = txtWhole.Text;
            keyPoint.InHouseStructure = txtInHouseStructure.Text;
            keyPoint.FirePrediction = txtFirePrediction.Text;
            keyPoint.FireResistanceRate = ddlFireResistanceRating.SelectedValue;
            keyPoint.FireDanger = txtFireDanger.Text;
            if (KeyUnit.UpdateKeyPoint(keyPoint))
            {
                Response.Redirect("keyPoint.aspx?uid=" + keyPoint.KeyUnitID);
            }
        }
        else
        {
            KeyPointInfo keyPoint = new KeyPointInfo();
            keyPoint.KeyUnitID = Request["uid"];
            keyPoint.KeyPointName = txtKeyPointName.Text;
            keyPoint.Parms = txtParms.Text;
            keyPoint.Substances = txtSubstances.Text;
            keyPoint.Whole = txtWhole.Text;
            keyPoint.InHouseStructure = txtInHouseStructure.Text;
            keyPoint.FirePrediction = txtFirePrediction.Text;
            keyPoint.FireResistanceRate = ddlFireResistanceRating.SelectedValue;
            keyPoint.FireDanger = txtFireDanger.Text;
            if (KeyUnit.InsertKeyPoint(keyPoint) > 0)
            {
                ListPageContral1.SetFirstPage();
                gvKeyPoint.PageIndex = 0;
                BindKeyPointList();
            }
        }
    }

    private void BindKeyPointList()
    {
        List<KeyPointInfo> infos = KeyUnit.GetKeyPointListByKeyUnitID(Request["uid"]);
        ListPageContral1.ItemCount = infos.Count;
        gvKeyPoint.DataSource = infos;
        gvKeyPoint.DataBind();
    }
    protected void gvKeyPoint_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        if (KeyUnit.DeleteKeyPoint(gvKeyPoint.DataKeys[e.RowIndex].Value.ToString()))
        {
            BindKeyPointList();
        }

    }
    protected void gvKeyPoint_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            System.Web.UI.WebControls.Label lblID = e.Row.FindControl("lblID") as System.Web.UI.WebControls.Label;
            lblID.Text = Convert.ToString(gvKeyPoint.PageSize * ListPageContral1.CurrentPageIndex + (e.Row.RowIndex + 1));
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
}
